package com.etone.smartAudit.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.etone.smartAudit.domain.City;
import com.etone.smartAudit.mapper.CityMapper;
import com.etone.smartAudit.vo.city.CityVO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: 蒋学伟
 * @create: 2020-07-08 08:41:15
 * @Description 城市管理
 */
@Service
@AllArgsConstructor
public class CityService {

    private CityMapper cityMapper;

    /**
     * 城市列表
     *
     * @param provinceId
     * @return
     */
    public List<CityVO> list(int provinceId) {
        City param = City.builder().provinceId(provinceId).build();
        QueryWrapper cityWrapper = new QueryWrapper<>(param);
        cityWrapper.orderByAsc("intSort");
        List<City> list = cityMapper.selectList(cityWrapper);
        return list.stream().map(city -> CityVO.builder().id(city.getId()).name(city.getName()).build()).collect(Collectors.toList());
    }
}
